<?php
/**
 *@author Connor <caokang@foxmail.com>
 *@todo
 *@link www.zeevin.com
 */
class Tags extends CActiveRecord{

	public function tableName(){
		return 'tags';
	}

	public static function model($className=__CLASS__){
		return parent::model($className);
	}
	
	//获取最新的热门标签，缓存每天更新一次
	public static function getHot(){
		$hot_tags = Yii::app()->fcache->get('HOT_TAGS');
		if(!$hot_tags){
			$rs = Yii::app()->db->createCommand()
					->select('id,tag_name,hot')
					->from('tags')
					->order('hot DESC')
					->limit(40)
					->query();

			foreach($rs as $v){
				$hot_tags[]=array($v[id],$v[tag_name]);
			}
			Yii::app()->fcache->set('HOT_TAGS',$hot_tags,86400);
		}

		return $hot_tags;
	}
//获取推荐标签
	public static function getForword(){
		$f_tags = Yii::app()->fcache->get('FORWORD_TAGS');
		if(!$f_tags){
			$rs = Yii::app()->db->createCommand()
					->select('id,tag_name,type')
					->from('tags')
					->where('forword=1')
					->order('hot DESC')
					->query();

			foreach($rs as $v){
				$f_tags[$v[type]][]=array($v[id],$v[tag_name]);
			}
			Yii::app()->fcache->set('FORWORD_TAGS',$f_tags,86400);
		}

		return $f_tags;
	}
	

	public static function className($id=false){
		$c = array('','音乐','体育','游戏','动漫','电影','电视剧','综艺','小说','明星','旅游','购物','宠物',);
		return $id?$c[$id]:$c;
	}
}